<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="demo">
        <School></School>
        <hr>
        <Person></Person>
    </div>
    <script>
        Vue.config.productionTip = false;

        const Hello = Vue.extend({
            template:`<h2>Hello Word</h2>`
        });

        //全局注册,所有组件均可使用此组件
        Vue.component('Hello',Hello)

        const School = Vue.extend({
            template:`<div class="school">
                    <Hello></Hello>
                    <h2>学校信息</h2>
                    <h3>学校名称:{{sname}}</h3>
                    <h3>学校地址:{{address}}</h3>
                    <button @click='sname += "~"'>修改学校名</button>
                    <button @click='welcome'>点击弹窗</button>
                </div>`,
                data() {
                return {
                    sname: '尚硅谷',
                    address: '宏福科技园'
                }
            },
            methods: {
                welcome() {
                    alert(`${this.sname}欢迎你`)
                }
            }
        })

        const Person = Vue.extend({
            //模板
            template: `<div class="person">
                    <h2>人员列表</h2>
                    <h3>姓名:{{pname}}</h3>
                    <h3>年龄:{{age}}</h3>
                    <button @click='age++'>点击年龄+1</button>
                    <button @click='speak'>点击弹窗</button>
                </div>`,
            //数据
            data() {
                return {
                    pname: '张三',
                    age: 18
                }
            },
            //方法
            methods:{
                speak() {
                    alert('Vue组件')
                }
            }
        })

        new Vue({
            el:'#demo',
            components:{
                School,
                Person
            }
        })
    </script>
</body>

</html>